#include #include const char* test_root_ca2 = int ms, s, m, h; unsigned long last_time; bool updated = false; const int motorPins[6][2] = { { 5, 18 }, { 19, 21 }, { 22, 23 }, { 13, 12 }, { 14, 27 }, { 26, 25 } }; bool motor_up[6] = {}; void setup() { // put your setup code here, to run once: Serial.begin(115200); for (int i = 0; i < 6; ++i) { pinMode(motorPins[i][0], OUTPUT); pinMode(motorPins[i][1], OUTPUT); digitalWrite(motorPins[i][0], LOW); digitalWrite(motorPins[i][1], LOW); Serial.printf("try %d\n", i); } while (!Serial) { delay(100); } // connect_wifi(); // get_wttr2(); } int find_first(const char* s, int len, char c) { for (int i = 0; i < len; i += 1) { if (s[i] == c) return i; } return -1; } void connect_wifi() { // We start by connecting to a WiFi network Serial.println(); Serial.println("******************************************************"); Serial.print("Connecting to "); Serial.println("FORMSHOP"); WiFi.begin("FORMSHOP", "formshop"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); } bool get_wttr2() { Serial.println("Connecting..."); WiFiClient client; if (!client.connect("api.open-meteo.com", 80)) { Serial.println("Failed to connect"); return false; } client.print( "GET /v1/forecast?latitude=31.2222&longitude=121.4581¤t=weather_code&timezone=Asia%2FShanghai&forecast_days=1 HTTP/1.1\r\n" "Host: api.open-meteo.com\r\n" "Connetion: close\r\n" "\r\n"); unsigned long timeout = millis(); while (client.available() == 0) { if (millis() - timeout > 5000) { Serial.println(">>> Client Timeout !"); client.stop(); return false; } } while (client.available()) { String line = client.readStringUntil('\n'); if (line[0] == '{') { // Serial.println(line); int i = line.lastIndexOf(':'); if (i < 0) { Serial.println("Error: no ':' in line"); return false; } int code = atoi(line.c_str() + i + 1); Serial.println(code); } } return true; } void loop() { const bool* current_state; switch (1) { case 2: current_state = (const bool[6]){ 0, 0, 0, 0, 0, 0 }; break; case 0: case 1: current_state = (const bool[6]){ 0, 1, 0, 0, 0, 0 }; break; case 3: case 45: case 48: current_state = (const bool[6]){ 0, 0, 1, 0, 0, 0 }; break; case 51: case 53: case 55: case 56: case 57: case 61: case 63: case 65: case 66: case 67: case 80: case 81: case 82: current_state = (const bool[6]){ 0, 0, 0, 1, 0, 0 }; break; case 71: case 73: case 75: case 77: case 85: case 86: current_state = (const bool[6]){ 0, 0, 0, 0, 1, 0 }; break; case 95: case 96: case 99: current_state = (const bool[6]){ 0, 0, 0, 0, 0, 1 }; break; default: current_state = (const bool[6]){ 0, 0, 0, 0, 0, 0 }; } for (int i = 0; i < 6; ++i) { motor_set_state(i, current_state[i]); } delay(700); for (int i = 0; i < 6; ++i) { motorStop(i); } } void motor_set_state(int motor, bool up) { if (up && !motor_up[motor]) { motorForward(motor); } if (!up && motor_up[motor]) { motorBackward(motor); } motor_up[motor] = up; } void motorForward(int motor) { int in1 = motorPins[motor][1]; int in2 = motorPins[motor][0]; analogWrite(in1, 150); analogWrite(in2, LOW); } void motorBackward(int motor) { int in1 = motorPins[motor][1]; int in2 = motorPins[motor][0]; analogWrite(in1, LOW); analogWrite(in2, 150); } void motorStop(int motor) { int in1 = motorPins[motor][1]; int in2 = motorPins[motor][0]; analogWrite(in1, LOW); analogWrite(in2, LOW); }